package com.carltechnology.mahjonggamecaculation.utils;

import org.greenrobot.eventbus.EventBus;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by WZTCM on 2016/6/1.
 */
public class Utils {
    //private static Utils instance = null;

    private static Utils instance = null;
    private EventBus eventBus = null;
    private RuntimeDataHelper runtimeDataHelper = null;
    public enum CONSTANT{
        ONBACKBUFFER_SIZE(99),
        ONBACKBUFFER_SMALL_SIZE(10);
        private int constant;
        CONSTANT(int constant){
            this.constant = constant;
        }
        public int getConstant(){
            return constant;
        }
    }


    public String getTodayDate(){
        String today =
                new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        return today;
    }
    public  EventBus getEventBus(){
        if (eventBus == null){
            eventBus = new EventBus();
        }
        return eventBus;
    }

    /**
     *
     * @param content
     * @return true if content is null or empty
     */
    public  boolean stringIsEmpty(String content){
        if (content == null|| content.isEmpty()){
            return true;
        }
        return false;
    }
    public static Utils getInstance(){
        if (instance == null){
            instance = new Utils();
        }
        return instance;
    }


    /**
     * 判定输入汉字
     * @param c
     * @return
     */
    public  boolean isChinese(char c) {
        Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
        if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
                || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
                || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
                || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
                || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
                || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
            return true;
        }
        return false;
    }

    /**
     * 检测String是否全是中文
     * @param name
     * @return
     */
    public  boolean checkNameChese(String name)
    {
        boolean res=true;
        char [] cTemp = name.toCharArray();
        for(int i=0;i<name.length();i++)
        {
            if(!isChinese(cTemp[i]))
            {
                res=false;
                break;
            }
        }
        return res;
    }

    public RuntimeDataHelper getRuntimeDataHelper(IRuntimeDataSolution solution) {
        if (runtimeDataHelper==null)
            runtimeDataHelper = new RuntimeDataHelper(solution);
        if (solution!=null)
            runtimeDataHelper.setiSolution(solution);
        return runtimeDataHelper;
    }
    public RuntimeDataHelper getRuntimeDataHelper() {
        if (runtimeDataHelper==null)
            runtimeDataHelper = new RuntimeDataHelper(null);

        return runtimeDataHelper;
    }
}
